﻿@*
    表单内容
*@

@using NewLife;
@using XCode;
@using XCode.Configuration;
@using NewLife.Cube;
@using NewLife.Cube.ViewModels;
@{
    var entity = Model as IEntity;
    var isNew = entity.IsNullKey;
    var fields = ViewBag.Fields as FieldCollection;

    var set = NewLife.Cube.Setting.Current;
    var cls = set.FormGroupClass;
    if (cls.IsNullOrEmpty())
    {
        cls = "col-xs-12 col-sm-6 col-lg-6 pt-2";
    }
}

<div class="card-body">

    @await Html.PartialAsync("_Form_Body_Message")

    <div class="row">
        @foreach (var item in fields)
        {
            if (item.Name.EqualIgnoreCase("CreateUserID", "CreateUser", "CreateTime", "CreateIP",
                "UpdateUserID", "UpdateUser", "UpdateTime", "UpdateIP"))
                continue;
            @*扩展信息单独显示*@
            if (item.Name.EqualIgnoreCase("Ex1", "Ex2", "Ex3", "Ex4", "Ex5", "Ex6")) continue;

            var des = item.Description.TrimStart(item.DisplayName).TrimStart(",", ".", "，", "。");
            var dataField = fields.GetField(item.Name) as ListField;
            var display = dataField?.DisplayName ?? item.DisplayName;

            if (item.Name.EqualIgnoreCase("permission"))
            {
                @await Html.PartialAsync("_Form_SetPermission", new { Role = entity })
            }
            else if (item.IsBigText())
            {
                <div class="">
                    <!-- 字段标签（含帮助说明信息） -->
                    <div class="d-inline-flex align-items-center">
                        <label class="col-form-label me-2" for="@item.Name">@display</label>
                        @if (!des.IsNullOrEmpty())
                        {
                            <div class="d-none d-md-block d-lg-block">
                                <i class="fas la-question-circle" data-bs-toggle="tooltip" title="@des"></i>
                            </div>
                        }
                    </div>

                    <!-- 字段编辑框 -->
                    <div class="flex-grow-1">
                        @await Html.PartialAsync("_Form_Editor", new ValueTuple<IEntity, DataField>(entity, item))
                    </div>
                    <span class="form-text text-muted d-sm-none"><span class="form-text text-muted">@des</span></span>
                </div>
            } else
            {
                <div class="@cls">
                    <!-- 字段标签（含帮助说明信息） -->
                    <div class="d-inline-flex align-items-center">
                        <label class="col-form-label me-2" for="@item.Name">@display</label>
                        @if (!des.IsNullOrEmpty())
                        {
                            <div class="d-none d-md-block d-lg-block">
                                <i class="fas la-question-circle" data-bs-toggle="tooltip" title="@des"></i>
                            </div>
                        }
                    </div>

                    <!-- 字段编辑框 -->
                    <div class="flex-grow-1">
                        @await Html.PartialAsync("_Form_Editor", new ValueTuple<IEntity, DataField>(entity, item))
                    </div>
                    <span class="form-text text-muted d-sm-none"><span class="form-text text-muted">@des</span></span>
                </div>
            }
        }
    </div>
</div>

@if (fields.Any(f => f.Name.Contains("Ex1")))
{
    @await Html.PartialAsync("_Form_Body_Extends", entity)
}

@if (!isNew)
{
    @await Html.PartialAsync("_Form_Body_Audits", entity)
}

